<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    {js href='/public/static/jquery/jquery-1.11.0.min.js' /}
    {js href='/public/static/layui/layui.js' /}
    {CSS href="/public/static/layui/css/layui.css" /}
    {CSS href="__ADDONSTATIC__/css/style.css" /}
    {js href='__STATIC__/admin/ueditor/ueditor.config.js' /}
    {js href='__STATIC__/admin/ueditor/ueditor.all.js' /}
</head>
<body>
<div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">

    <div class="layui-tab-content">
<div class="forms-content">
    <form name="form2" class="layui-form" action="">
        <div class="layui-form-item">
            <label class="layui-form-label">标题</label>
            <div class="layui-input-block">
                <input type="text" name="title" value="{$form.title}" required lay-verify="required" placeholder="请输入名称" autocomplete="off"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">封面图</label>
            <div class="layui-input-block">
                {:hook('Upload',['type'=>'image','name'=>'cover','value'=>$form.cover,'material'=>true])}
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">作者</label>
            <div class="layui-input-block">
                <input type="text" name="author" value="{$form.author}"  placeholder="请输入名称" autocomplete="off"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">原文链接</label>
            <div class="layui-input-block">
                <input type="text" name="content_source_url" value="{$form.content_source_url}"  placeholder="请输入名称" autocomplete="off"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">正文</label>
            <div class="layui-input-block">
                <div class="controls" id="discripContainer">
                    <textarea id="tareaProductDiscrip1" name="discripArea" style=" width: 100%; display: none;"></textarea>
                    <script id="editor" type="text/plain" style="width: 100%; height: 400px;">{$form.content|raw}</script>
                    </div>
            </div>
        </div>

        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">摘要</label>
            <div class="layui-input-block">
                <textarea name="digest" placeholder="请输入描述" class="layui-textarea">{$form.digest}</textarea>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">发布状态</label>
            <div class="layui-input-block">
                <input type="checkbox" {if condition="$form.show == 1"}checked{/if} lay-skin="switch" name="show">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">置顶</label>
            <div class="layui-input-block">
                <input type="checkbox" {if condition="$form.top == 1"}checked{/if} lay-skin="switch" name="top">
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
                <button type="button" onclick="location.href='{:addonUrl(\'article\')}'" class="layui-btn layui-btn-primary">返回</button>
            </div>
        </div>
    </form>
</div>
    </div>
</div>

<script>
    var ue = UE.getEditor('editor', {scaleEnabled: false});
                        UE.Editor.prototype._bkGetActionUrl = UE.Editor.prototype.getActionUrl;
                        UE.Editor.prototype.getActionUrl = function(action) {
                            if (action == 'uploadimage' || action == 'uploadscrawl' || action == 'uploadimage') {
                                return '{$uploadImg}';
                            } else if (action == 'uploadvideo') {
                                return 'video';
                            } else if (action == 'listimage') {
                                return "{:url('mp/mp/getLocalImage')}";
                            }
                            else {
                                return this._bkGetActionUrl.call(this, action);
                            }
                        }
    layui.use(['form', 'layer'], function () {
        var form = layui.form;
        var layer = layui.layer;

        form.on('submit(formDemo)', function (data) {
            var loadIndex = layer.load(1);
            data.field.content = UE.getEditor('editor').getContent();
            $.post('', data.field, function (res) {
                layer.close(loadIndex);
                parent.layer.msg(res.msg);
            }).error(function (error) {
                parent.layer.alert('500 Internal Server Error');
                layer.close(loadIndex)
            })
            return false;
        });
    });
</script>
</body>
</html>